package cn.com.zhuxulin.android.demos.activities;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
import android.widget.TextView;
import cn.com.zhuxulin.android.demos.R;
import cn.com.zhuxulin.android.demos.bussiness.TelephonyInfo;

public class TelephonyManagerDemos extends Activity {
	private TextView result = null;
	private TelephonyManager mTManager = null;
	private GsmCellLocation gcl = null;
	private static String TAG = "TelephonyManagerDemos";
	private String NO = null;
	private String IMSI = null;
	private int mcc = -1;
	private int mnc = -1;
	private int cid = -1;
	private int lac = -1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.telephony_manager_demos);
		this.result = (TextView) findViewById(R.id.result);
		mTManager = (TelephonyManager) this
				.getSystemService(Context.TELEPHONY_SERVICE);
		gcl = (GsmCellLocation) mTManager.getCellLocation();

	}

	@Override
	protected void onStart() {
		super.onStart();
		cid = gcl.getCid();
		lac = gcl.getLac();
		NO = mTManager.getNetworkOperator();
		IMSI = mTManager.getSubscriberId();
		Log.e(TAG, "NO:" + NO);
		Log.e(TAG, "IMSI:" + IMSI);
		mcc = Integer.valueOf(NO.substring(0, 3));
		mnc = Integer.valueOf(NO.substring(3, 5));
		String getNumber = "";
		getNumber += ("cid:" + cid + "\n");
		getNumber += ("lac:" + lac + "\n");
		getNumber += ("mcc:" + mcc + "\n");
		getNumber += ("mnc:" + mnc + "\n");
		Log.e(TAG, getNumber);
		String info = new TelephonyInfo(getApplicationContext())
				.getAllInfo();
		result.setText("NO:" + NO + "\nIMSI:" + IMSI + "\n" + getNumber + "\n"
				+ info);
		Log.e(TAG, "INFO:" + info);
	}
}
